<template>
    <div>
        <el-card class="box-card" shadow="never">
            <!--导航栏-->
            <el-breadcrumb separator-class="el-icon-arrow-right">
                <el-breadcrumb-item>横幅管理</el-breadcrumb-item>
                <el-breadcrumb-item>横幅列表</el-breadcrumb-item>
            </el-breadcrumb>
            <!--分割线-->
            <div class="yx_line"></div>
            <el-row :gutter="10" style="margin-top:20px;">
               <el-col :span='6'>
                  <el-select v-model="type" placeholder="发布位置" clearable>
                      <el-option
                              v-for="item in allbannertype"
                              :key="item.value"
                              :label="item.label"
                              :value="item.value">
                      </el-option>
                  </el-select>
               </el-col>
            </el-row>
            <!--添加按钮  条件搜索区 总计24栏-->
            <el-row class="yx_el_row">
                <el-col>
                    <el-button type="success" plain @click="search">筛选</el-button>
                    <el-button type="primary" plain @click="edit(-1,1)">添加</el-button>
                </el-col>
            </el-row>
            <el-table class="yx_table" border :data="list">
                <el-table-column prop="index" label="序号" width="100">
                </el-table-column>
                <el-table-column prop="name" label="名称" width="180">
                </el-table-column>
                <el-table-column prop="type" label="展示位置" width="180">
                </el-table-column>
                <el-table-column prop="sort" label="顺序" width="100">
                </el-table-column>
                <el-table-column prop="url" label="缩略图" width="180">
                    <template slot-scope="scope">
                        <el-image :src="scope.row.url"> </el-image>
                    </template>
                </el-table-column>
                <el-table-column prop="enabled" label="状态" width="100">
                </el-table-column>
                <el-table-column prop="create_time" label="创建时间" width="100">
                </el-table-column>
                <el-table-column  label="操作">
                    <template slot-scope="scope">
                        <el-tooltip class="item" effect="dark" content="编辑" placement="bottom-start">
                            <el-button type="primary" icon="el-icon-edit" @click="edit(scope.row.id,2)" circle></el-button>
                        </el-tooltip>
                        <el-tooltip class="item" effect="dark" content="查看"  placement="bottom-start">
                            <el-button type="info" icon="el-icon-notebook-1" @click="edit(scope.row.id,0)" circle></el-button>
                        </el-tooltip>
                        <el-tooltip class="item" effect="dark" content="删除" placement="bottom-start">
                            <el-button type="warning" icon="el-icon-delete" @click="del(scope.row.id)" circle></el-button>
                        </el-tooltip>
                    </template>
                </el-table-column>
            </el-table>
            <Pagination :total_count="total_count" :getList="getList"></Pagination>
        </el-card>
    </div>
</template>

<script>
    import Pagination from '@/components/Pagination.vue';
    import { getBannerList,delBanner,getAllBannerType } from '@/api/banner.js';
    export default {
        name: 'BannerList',
        inject:['reload'],
        components:{ Pagination },
        data() {
            return {
                list:[],
                total_count:0,
                type:'',
                allbannertype:this.$store.state.allbannertype
            }
        },
        methods: {
            getList(current_page,page_size){
                var send_data={
                    api_token:this.$store.getters.getSessionId,
                    current_page:current_page,
                    page_size:page_size,
                    type:this.type==''?-1:this.type
                }
                let that=this;
                getBannerList(send_data).then(function(response){
                   if(response.data.code==1){
                     that.list=response.data.list;
                     that.total_count=response.data.total_count;
                   }
                })
            },
            search(){
               this.getList(1,this.$store.state.default_page_size);
            },
            edit(id,edit_type){
                this.$router.push({
                    name:'banneredit',
                    params:{id:id,edit_type:edit_type}
                });
            },
            del(id){
                let that=this;
                //弹框提示
                this.$confirm('确认删除, 是否继续?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then((e) => {
                    var send_data={
                        api_token : that.$store.getters.getSessionId,
                        id:id
                    };
                    delBanner(send_data).then(function(response){
                        let type=response.data.code==1?'success':'error';
                        let msg=response.data.code==1?'删除成功':'删除失败'
                        that.$message({
                            message:msg,
                            duration:1200,
                            type:type,
                            onClose:function(e){
                                that.reload();
                            }
                        });
                    })
                })
            }
        },
        created() {
            this.getList(1,this.$store.state.default_page_size);
        }
    }
</script>

<style>
    @import url('../../assets/css/table.css');
</style>
